/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.attence;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.attence.HolidayRecord;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Service("holidayrecordService")
public class HolidayRecordServiceImpl implements HolidayRecordService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of HolidayRecord
     ****************************************/
    public void insert(HolidayRecord holidayrecord) throws Exception {
        holidayrecord.setRecordid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(holidayrecord);
    }

    /****************************************
     * Update a instace of HolidayRecord
     ****************************************/
    public void update(HolidayRecord holidayrecord) throws Exception {
        iDataSet4iBatis.update(holidayrecord);
    }

    /****************************************
     * Delete a instace of HolidayRecord
     ****************************************/
    public void delete(HolidayRecord holidayrecord) throws Exception {
        iDataSet4iBatis.delete(holidayrecord);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(HolidayRecord holidayrecord) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(HolidayRecord holidayrecord) throws Exception {
        String statementId = holidayrecord.getStatmentId();
        String mainId = holidayrecord.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> holidayrecordList = new ArrayList<BaseModel>();
        for (String id : ids) {
            HolidayRecord model = new HolidayRecord();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            holidayrecordList.add(model);
        }
        iDataSet4iBatis.batchDelete(holidayrecordList);
    }

    /****************************************
     * Query instaces of HolidayRecord
     ****************************************/
    public List<BaseModel> queryAsList(HolidayRecord holidayrecord) throws Exception {
        String queryListStatement = "";
        if (holidayrecord.isPaging()) {
            queryListStatement = holidayrecord.getStatmentId();
            holidayrecord.setStatmentId("HolidayRecord.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(holidayrecord);
            holidayrecord.setTotalCount(baseModel.getTotalCount());
            holidayrecord.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(holidayrecord);
    }

    /****************************************
     * Query a instaces of HolidayRecord
     ****************************************/
    public BaseModel queryAsObject(HolidayRecord holidayrecord) throws Exception {
        return iDataSet4iBatis.queryAsObject(holidayrecord);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
